﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;//引用命名空间

namespace MotionGTS
{
    public partial class Frm_Show : Form
    {
        //实例化窗体
        Frm_Coordinates coordinates = null;
        //JOP运动窗体
        Frm_Jop frm_Jop = null;
        //P2P运动窗体
        Frm_P2P frm_P2P = null;
        //GDI运动窗体
        Frm_GDI frm_GDI = null;

        public Frm_Show()
        {
            InitializeComponent();
            //JOP运动窗体
            frm_Jop = new Frm_Jop();
            //P2P运动窗体
            frm_P2P = new Frm_P2P();
            //GDI运动窗体
            frm_GDI = new Frm_GDI();
            //实例化窗体
            coordinates = new Frm_Coordinates();

            //检查文件是否存在，如果存在就加载，如果不存在就创建使用默认布局
            if (File.Exists("./DockPanel.xml"))
            {
                //读取配置文件，然后进行加载
                this.dockPanel1.LoadFromXml("./DockPanel.xml", GetDockContentForm);
            }
            else
            {
                //默认显示 显示停靠的位置
                coordinates.Show(this.dockPanel1,DockState.DockLeft);
                frm_Jop.Show(this.dockPanel1,DockState.Document);
                frm_P2P.Show(this.dockPanel1, DockState.Document);
                frm_GDI.Show(this.dockPanel1, DockState.Document);                
            }

        }

        public DockContent GetDockContentForm(string PersistString)
        {
            if (coordinates.GetType().ToString()== PersistString)
            {
                return coordinates;
            }
            else if (frm_Jop.GetType().ToString() == PersistString)
            {
                return frm_Jop;
            }
            else if (frm_P2P.GetType().ToString() == PersistString)
            {
                return frm_P2P;
            }
            else if (frm_GDI.GetType().ToString() == PersistString)
            {
                return frm_GDI;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 窗体关闭前保存布局
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_Show_FormClosing(object sender, FormClosingEventArgs e)
        {
            //保存窗体布局
            this.dockPanel1.SaveAsXml("./DockPanel.xml");
        }
    }
}
